package coms.ejb;

import coms.dataaccess.dao.ConferenceItemBookingDAO;
import coms.dataaccess.hibernate.HibernateDAOFactory;
import coms.dto.*;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import coms.dto.User;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.Stateless;

@Stateless (mappedName="ConferenceItemBookingBean")
public class ConferenceItemBookingBean extends GenericBean<ConferenceItemBooking> implements ConferenceItemBookingBeanRemote{
    
  private ConferenceItemBookingDAO conferenceItemBookingDAO;
    
    @PostConstruct
    public void construct() {
        super.construct();
        HibernateDAOFactory factory = new HibernateDAOFactory();
        conferenceItemBookingDAO = factory.getConferenceItemBookingDAO();
    }
   
    @Override
    public List<ConferenceItemBooking> getByConferenceItem(ConferenceItem conferenceItem) {
          ConferenceItemBooking confItemBooking = new ConferenceItemBooking();
          confItemBooking.setConferenceItem(conferenceItem);
          List<ConferenceItemBooking> confItemBookingList = new ArrayList<ConferenceItemBooking>();
        try {
            confItemBookingList = conferenceItemBookingDAO.search(confItemBooking);
        } catch (SQLException ex) {
            Logger.getLogger(ConferenceRegistrationBean.class.getName()).log(Level.SEVERE, null, ex);
        }
         return confItemBookingList;
    }
    
    @Override
    public List<ConferenceItemBooking> getByParticipant(User user) {
          ConferenceItemBooking confItemBooking = new ConferenceItemBooking();
          confItemBooking.setParticipant(user);
          List<ConferenceItemBooking> confItemBookingList = new ArrayList<ConferenceItemBooking>();
        try {
            confItemBookingList = conferenceItemBookingDAO.search(confItemBooking);
        } catch (SQLException ex) {
            Logger.getLogger(ConferenceRegistrationBean.class.getName()).log(Level.SEVERE, null, ex);
        }
         return confItemBookingList;
    }

    @Override
    public List<ConferenceItemBooking> getByConferenceAndParticipant(User user, Conference conference) {
        return conferenceItemBookingDAO.searchByParticipantAndConference(user, conference);
    }
    
}